@extends('common/member')
@section('title','首页')
@section('cnt')
<style>
    .text-center{
        font-size: 1.3em;
    }
</style>
<div class="text-right" style="margin:1em;">
    <a href="{{ route('user/create') }}" class="btn btn-success">添加</a>
</div>
<table class="table table-condensed">
	<thead>
		<tr>
			<th class="text-center">Id</th>
			<th class="text-center">用户名</th>
			<th class="text-center">Email</th>
			<th class="text-center">QQ</th>
			<th class="text-center">操作</th>
		</tr>
	</thead>
	<tbody>
        @foreach ($data as $item)
            <tr>
                <td class="text-center">{{$item->id}}</td>
                <td class="text-center">{{$item->username}}</td>
                <td class="text-center">{{$item->email=='' ? '没有邮箱' : $item->email}}</td>
                <td class="text-center">{{$item->qq}}</td>
                <td class="text-center">
                    <a href="{{ route('user/edit',['id'=>$item->id]) }}" class="btn btn-xs btn-info">修改</a>
                    <a href="{{ route('user/del',['id'=>$item->id]) }}" class="btn btn-xs btn-danger del">删除</a>
                </td>
            </tr>
        @endforeach
	</tbody>
</table>
@endsection

@section('js')
    <script>
        // csrf凭证
        let _token = "{{ csrf_token() }}";
        $('.del').click(function(){
            let url = $(this).attr('href');
            let type = 'DELETE';
            let data = {_token};

            // 发起ajax请求
            let bool = confirm('确认删除此用户吗？');
            if(bool){
                $.ajax({
                    url,
                    type,
                    data
                }).then(ret=>{
                    $(this).parents('tr').remove();
                })
            }
            return false;
        })
    </script>
@endsection